﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Helper;
using System.ComponentModel;
namespace CoreData
{
    public class Subject
    {
       // [Description("ID")]
            public long ID{get;set;}
        [Description("Mã môn học")]
            public string Code{get;set;}
        [Description("Tên môn học")]
            public string Name{get;set;}
        [Description("Ghi chú")]
            public string Description{get;set;}
       // [Description("Ghi chú")]
        public int Semester { get; set; }
     //   [Description("BranchID")]
        public long BranchID { get; set; }
        [Description("Số học phần")]
        public int Factor { get; set; }
        [Description("Sử dụng")]
            public bool Active{get;set;}
        public bool IsDeleted { get; set; }
        [Description("Ngành")]
        public string BranchExt { get; set; }
         [Description("Học kỳ")]
        public string SemesterExt { get; set; }
         
        public Subject()
        {       
                            Code ="";   
                            Name ="";   
                            Description ="";
                            IsDeleted = false;
                            Factor = 1;
        
        }
        
       static Subject DynamicCast<T>(object row_data, object row_header) where T : Subject
       {
           // row_data : DataRow
           // row_header : DataColumnCollection
           Subject ret = new Subject();
           DataRow dt = (DataRow)row_data;

           foreach (DataColumn column in (DataColumnCollection)row_header)
           {
               switch (column.ColumnName)
               {
                      case  "ID":
                        ret.ID = ConvertObject.ToLong(dt[column]);
                       break;
                      case  "Code":
                        ret.Code = ConvertObject.ToString(dt[column]);
                       break;
                      case  "Name":
                        ret.Name = ConvertObject.ToString(dt[column]);
                       break;
                      case  "Description":
                        ret.Description = ConvertObject.ToString(dt[column]);
                       break;
                      case "BranchName":
                       ret.BranchExt = ConvertObject.ToString(dt[column]);
                       break;
                      case  "BranchID":
                       ret.BranchID = ConvertObject.ToLong(dt[column]);
                       break;
                      
                      case  "Active":
                        ret.Active = ConvertObject.ToBool(dt[column]);
                       break;
                      case "Factor":
                       ret.Factor = ConvertObject.ToInt(dt[column]);
                       break;
                      case "IsDeleted":
                       ret.IsDeleted = ConvertObject.ToBool(dt[column]);
                       break;
                      case "Semester":
                       {
                           ret.Semester = ConvertObject.ToInt(dt[column]);
                           if(ret.Semester==0)
                               ret.SemesterExt ="Học kỳ I";
                           else
                               ret.SemesterExt ="Học kỳ II";
                       }
                       break;
                   default:
                       break;
               }
           }

           return ret;
       }
        
    }
}
